<!DOCTYPE html>
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <meta charset="UTF-8">
    <title>Book Manage System </title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <style>
        nav {
            font-size: 1.5rem;
            background-color: #21D4FD;
            background-image: -webkit-linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
            background-image: -moz-linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
            background-image: -o-linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
            background-image: linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
        }

        h1 {
            font-size: 2rem;
            color: white;
        }

        li {
            margin: 10px 20px;
        }

        #searchBox {
            width: 300px;
            float: right;
        }
        #registerbtn{
            position: fixed;
            right: 20px;
            bottom: 20px;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-primary navbar-dark">
    <ul class="navbar-nav">
        <li>
            <h1><a th:href="@{/}" style="color: white; text-decoration: none">Book Manage System </a></h1>
        </li>
        <li class="nav-item">
            <a class="nav-link" th:href="@{/admin/book/getAll}">Book Manage </a>
        </li>
        <li class="nav-item">
            <a class="nav-link active" th:href="@{/admin/reader/getAll}">Reader Manage </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" th:href="@{/admin/record/getAll}">Borrow Manage</a>
        </li>
        <li class="nav-item">
            <a class="nav-link " th:href="@{/admin/system/getAll}">parameter settings</a>
        </li>
    </ul>
    <div class="text-white" style="font-size: medium; position: absolute; bottom: 30px; right: 40px">
        <div class="dropdown">
            <a class="dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true"
               aria-expanded="false"
               th:text="${session.name}+', Hello'">
            </a>
            <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                <a class="dropdown-item" th:href="@{/user/toInfoPage}" sec:authorize="hasRole('USER')">Person
                    Information</a>
                <a class="dropdown-item" th:href="@{/toChPwdPage}">Modify Password</a>
                <a class="dropdown-item" th:href="@{/logout}">Logout</a>
            </div>
        </div>
    </div>
</nav>

<div class="modal fade" id="register" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">注  册</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <!--注册功能实现-->
                <div>
                    <form th:action="@{/admin/reader/registerById}" method="post">
                        <div class="form-group">
                            <label for="username" class="">username:</label>
                            <input type="text" class="form-control" id="username" name="username">
                        </div>
                        <div class="form-group">
                            <label for="password" class="">password:</label>
                            <input type="text" class="form-control" id="password" name="password" value="1">
                        </div>
                        <input type="submit" class="btn btn-primary btn-lg" value="register" style="margin-top: 20px">
                        <button type="button" class="btn btn-secondary btn-lg" data-dismiss="modal" style="margin-top: 20px">Close</button>
                    </form>
                </div>

            </div>
            <div class="modal-footer">
            </div>
        </div>
    </div>
</div>

<div class="container" style="margin-top: 40px">

    <button type="button" id="registerbtn" class="btn btn-light btn-lg" style="margin: 20px" data-toggle="modal" data-target="#register">
        register
    </button>
    <form th:action="@{/admin/reader/searchById}" id="returnBox">
        <div class="input-group">
            <input type="text" class="form-control" placeholder="Type the readerId to search..." name="readerId">
            <input type="submit" class="input-group-append btn btn-success" value="Search">
        </div>
    </form>

    <form th:action="@{/admin/reader/deleteById}" id="searchBox">
        <div class="input-group">
            <input type="text" class="form-control" placeholder="Type the readerId to delete..." name="readerId">
            <input type="submit" class="input-group-append btn btn-success" value="Delete">
        </div>
    </form>

    <table class="table table-hover" style="margin-top: 20px">
        <thead>
        <tr>
            <th>id</th>
            <th>name</th>
            <th>gender</th>
            <th>registerTime</th>
            <th>address</th>
            <th>phoneNumber</th>
            <th>barcode</th>

        </tr>
        </thead>
        <tbody>
        <tr th:each="reader : ${readers}">
            <td th:text="${reader.getReaderId()}"></td>
            <td th:text="${reader.getName()}"></td>
            <td th:text="${reader.getGender()}"></td>
            <td th:text="${#dates.format(reader.getRegisterTime(),'yyyy-MM-dd')}"></td>
            <td th:text="${reader.getAddress()}"></td>
            <td th:text="${reader.getPhoneNumber()}"></td>
            <td>
                <img th:src="@{${reader.getBarcode}}">
            </td>
        </tr>
        </tbody>
    </table>
</div>

<script th:inline="javascript">
    let isFailed = [[${failed}]];
    if(isFailed == true){
        alert("the reader has borrowed one or more books, delete failed!!");
    }
</script>


<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>
</html>
